package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.YtCustomerInvoice;
import com.ruoyi.system.service.IYtCustomerInvoiceService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户发票Controller
 * 
 * @author magichaohao
 * @date 2021-05-13
 */
@Controller
@RequestMapping("/system/invoice")
public class YtCustomerInvoiceController extends BaseController
{
    private String prefix = "system/invoice";

    @Autowired
    private IYtCustomerInvoiceService ytCustomerInvoiceService;

    @RequiresPermissions("system:invoice:view")
    @GetMapping()
    public String invoice()
    {
        return prefix + "/invoice";
    }

    /**
     * 查询客户发票列表
     */
    @RequiresPermissions("system:invoice:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YtCustomerInvoice ytCustomerInvoice)
    {
        startPage();
        List<YtCustomerInvoice> list = ytCustomerInvoiceService.selectYtCustomerInvoiceList(ytCustomerInvoice);
        return getDataTable(list);
    }

    /**
     * 导出客户发票列表
     */
    @RequiresPermissions("system:invoice:export")
    @Log(title = "客户发票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YtCustomerInvoice ytCustomerInvoice)
    {
        List<YtCustomerInvoice> list = ytCustomerInvoiceService.selectYtCustomerInvoiceList(ytCustomerInvoice);
        ExcelUtil<YtCustomerInvoice> util = new ExcelUtil<YtCustomerInvoice>(YtCustomerInvoice.class);
        return util.exportExcel(list, "客户发票数据");
    }

    /**
     * 新增客户发票
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存客户发票
     */
    @RequiresPermissions("system:invoice:add")
    @Log(title = "客户发票", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YtCustomerInvoice ytCustomerInvoice)
    {
        return toAjax(ytCustomerInvoiceService.insertYtCustomerInvoice(ytCustomerInvoice));
    }

    /**
     * 修改客户发票
     */
    @GetMapping("/edit/{clientInvoiceId}")
    public String edit(@PathVariable("clientInvoiceId") Long clientInvoiceId, ModelMap mmap)
    {
        YtCustomerInvoice ytCustomerInvoice = ytCustomerInvoiceService.selectYtCustomerInvoiceById(clientInvoiceId);
        mmap.put("ytCustomerInvoice", ytCustomerInvoice);
        return prefix + "/edit";
    }

    /**
     * 修改保存客户发票
     */
    @RequiresPermissions("system:invoice:edit")
    @Log(title = "客户发票", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YtCustomerInvoice ytCustomerInvoice)
    {
        return toAjax(ytCustomerInvoiceService.updateYtCustomerInvoice(ytCustomerInvoice));
    }

    /**
     * 删除客户发票
     */
    @RequiresPermissions("system:invoice:remove")
    @Log(title = "客户发票", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ytCustomerInvoiceService.deleteYtCustomerInvoiceByIds(ids));
    }
}
